package homework2;

public class Student implements Cloneable {
    private String name;
    private int age;

    // 异常的处理方法, 在方法的末尾添加  throws Exception
    public static void main(String[] args) throws Exception {
        Student student = new Student();
        student.name = "赵四";
        student.age = 11;
        Object obj = student.clone();
        Student cloneStu = (Student) obj;
        System.out.println(cloneStu.name);
        System.out.println(cloneStu.age);

        // 浅克隆, 克隆的引用数据类型指向同一个堆内存的地址值
        System.out.println(System.identityHashCode(student.name));//460141958
        System.out.println(System.identityHashCode(cloneStu.name));//460141958
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}